<?php
namespace app\index\controller;

class Index
{
    public function index()
    {
        return 'Yujiso';
    }
    public function title(){
        $titles = [
            'code' => '采购单号',
            'purchase_company_str' => '采购公司',
            'supplier_company_str' => '供应商',
            'receipt_warehouse_str' => '收货仓库',
            'arrival_date' => '预计到仓时间',
            'type_str' => '类型',
            'sku_num' => 'sku',
            'money' => '总金额',
            'ctime' => '创建时间'
        ];
        $temp=[];
        foreach ($titles as $k=>$v){
            $temp[]=",{field: '{$k}', title: '{$v}'}";
        }
        exit(join('<br/>',$temp));
    }
    public function create(){
        $controller=input('controller');
        if(empty($controller)){
            returnArr(500,'控制器名称不能为空');
        }
        $listDir=[];
        $listDir[]=ROOT_PATH.'public/src/views/'.$controller;//前端模板目录
        //创建目录
        foreach ($listDir as $dir) {
            // 目录不存在则创建目录
            !is_dir($dir) && mkdir($dir, 0755, true);
        }
        $controllerFile=ROOT_PATH.'application/index/controller/'.$controller.'.php';//控制器
        $content = "<?php\n\nnamespace app\index\controller;\n\nuse app\common\YujisoController;\n\nclass {$controller} extends YujisoController\n{\n    public function __construct(){\n        parent::__construct();\n    }\n}";
        if (!is_file($controllerFile)) {
            file_put_contents($controllerFile, $content);
        }
        $viewsFile=$listDir[0].'/index.html';//前端模板
        $content = file_get_contents(ROOT_PATH.'public/src/views/User/getList.html');
        if (!is_file($viewsFile)) {
            file_put_contents($viewsFile, $content);
        }

        $serviceFile=ROOT_PATH.'application/index/service/'.$controller.'Service.php';//前端模板
        $content = "<?php\n\nnamespace app\index\service;\n\nclass {$controller}Service\n{\n\n}";
        if (!is_file($serviceFile)) {
            file_put_contents($serviceFile, $content);
        }
        $modelFile=ROOT_PATH.'application/index/model/'.$controller.'Model.php';//前端模板
        $content = "<?php\n\nnamespace app\index\model;\n\nuse  think\Db;\n\nclass {$controller}Model\n{\n\n}";
        if (!is_file($modelFile)) {
            file_put_contents($modelFile, $content);
        }
        returnJson(1,'创建成功');
    }
}
